<template>
	<view>
		<map style="width: 100%; height: 100vh;" @tap='handleMapClick' @callouttap='handleClickMarker'
			@markertap='handleClickMarker' :latitude="latitude" :longitude="longitude" :markers="covers">
			<cover-view class="controls-address" :style="{bottom: selectMarkerId?'460rpx':'60rpx'}"
				@click="handleInitAddress">
				<cover-image src="/static/images/add-d.png" mode="widthFix"></cover-image>
			</cover-view>
			<cover-view @click="handleNavToRoad" v-show="!selectMarkerId" class="controls-roads"
				:style="{bottom: selectMarkerId?'400rpx':'60rpx'}">
				<!-- <cover-view class="road-name"> -->
					<cover-image src="/static/images/road-btn.png" mode="widthFix"></cover-image>
					<!-- <cover-image src="/static/images/road-btn.png" mode="widthFix"></cover-image> -->
				<!-- </cover-view> -->
			</cover-view>
			<cover-view class="covers-content" @click="handleNavToDetail" v-show="selectMarkerId">
				<cover-view class="content-cc">
					<cover-view class="content-t">
						<cover-view class="title">西河们大堂</cover-view>
						<cover-view class="sub-title">1144.54公里
							<cover-view class="status">客流量较小</cover-view>
						</cover-view>
						<cover-view class="desc">
							西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂公里西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂西河们大堂公里</cover-view>
					</cover-view>
					<cover-view class="content-r">
						<cover-image src="/static/images/play.png" mode="widthFix"></cover-image>
						<cover-view class="len">02:05</cover-view>
					</cover-view>
				</cover-view>
				<cover-view class="btm-operas">
					<cover-view class="btn">
						<cover-image src="/static/images/XQ.png" mode="widthFix"></cover-image>
						<cover-view>分享</cover-view>
					</cover-view>
					<cover-view class="btn">
						<cover-image src="/static/images/DK.png" mode="widthFix"></cover-image>
						<cover-view>详情</cover-view>
					</cover-view>
				</cover-view>
			</cover-view>
		</map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectMarkerId: '',
				latitude: 39.909,
				longitude: 116.39742,
				covers: [{
					id: 1,
					latitude: 39.909,
					longitude: 116.39742,
					width: 20,
					height: 20,
					iconPath: '/static/logo.png',
					noAvtiveIcon: '/static/logo.png',
					avtiveIcon: '/static/images/road-btn.png',
					callout: {
						content: "文华店", // 车牌信息
						display: "ALWAYS",
						fontWeight: "bold",
						color: "#fff", //文本颜色
						fontSize: "12px",
						bgColor: "rgba(114,96,72)", //背景色
						padding: 5, //文本边缘留白
						textAlign: "center",
					},
				}, {
					id: 2,
					latitude: 39.909,
					longitude: 116.38742,
					width: 20,
					height: 20,
					iconPath: '../../static/logo.png',
					noAvtiveIcon: '/static/logo.png',
					avtiveIcon: '/static/images/road-btn.png',
					callout: {
						content: "文华店", // 车牌信息
						display: "ALWAYS",
						fontWeight: "bold",
						color: "#fff", //文本颜色
						fontSize: "12px",
						bgColor: "rgba(114,96,72)", //背景色
						padding: 5, //文本边缘留白
						textAlign: "center",
					},
				}],
			};
		},
		methods: {
			handleNavToDetail() {
				uni.navigateTo({
					url: '/pages/sceneryDetail/sceneryDetail'
				})
			},
			handleNavToRoad() {
				uni.navigateTo({
					url: '/pages/roadList/roadList'
				})
			},
			handleInitAddress() {
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
					},
					fail(r) {
						console.log(r)
					}
				});
			},
			handleMapClick() {
				this.covers.forEach(it => {
					it.width = 20;
					it.height = 20;
					it.iconPath = it.noAvtiveIcon
				})
				this.selectMarkerId = ''
			},
			handleClickMarker(e) {
				console.log(e)
				this.selectMarkerId = e.detail.markerId
				this.covers.forEach(it => {
					if (it.id == e.detail.markerId) {
						it.width = 30;
						it.height = 30;
						it.iconPath = it.avtiveIcon
					} else {
						it.width = 20;
						it.height = 20;
						it.iconPath = it.noAvtiveIcon
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.controls-address {
		width: 90upx;
		height: 90upx;
		background-color: #333;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		left: 20upx;
		bottom: 60upx;
		transition: .3s;
		z-index: 999;

		image {
			width: 140upx;
			height: 140upx;
		}
	}

	.covers-content {
		position: absolute;
		width: calc(100% - 60upx);
		left: 30upx;
		background-color: #fff;
		border-radius: 8upx;
		bottom: 60upx;
		z-index: 999;
		padding-top: 22upx;

		box-sizing: border-box;

		.content-cc {
			display: flex;
		}

		.content-r {
			width: 160upx;
			padding-right: 30upx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			image {
				width: 140upx;
				height: 140upx;
			}

			.len {
				font-size: 28upx;
				color: $uni-color-bg-z;
				margin-top: 22upx;
			}
		}

		.content-t {
			padding: 0 30upx;
			box-sizing: border-box;

			.title {
				font-size: 36upx;
				font-weight: 800;
			}

			.sub-title {
				font-size: 28upx;
				color: $uni-text-color-sub;
				margin-top: 20upx;
				margin-bottom: 20upx;
				display: flex;

				.status {
					color: $uni-color-bg-z;
					margin-left: 30upx;
				}
			}

			.desc {
				font-size: 28upx;
				color: $uni-text-color-sub;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				line-height: 1.6;
				white-space: break-spaces;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}
		}

		.btm-operas {
			border-top: 1upx solid $uni-border-color;
			display: flex;
			margin-top: 22upx;

			.btn {
				width: 50%;
				text-align: center;
				padding: 32upx 0;
				display: flex;
				align-items: center;
				justify-content: center;
				border-right: 1upx solid $uni-border-color;

				image {
					width: 40upx;
					margin-right: 12upx;
				}

				&:last-child {
					border: 0 none;
				}
			}
		}
	}

	.controls-roads {
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		background-color: #fff;
		border-radius: 50%;
		width: 160upx;
		height: 160upx;
		z-index: 999;
		bottom: 20upx;
		padding: 12upx;

		.road-name {
			image {
				width: 160upx;
				height: 160upx;
			}
		}
	}
</style>